<?php
JLoader::register("PJobpositionHelper", OC::$SERVERROOT.'/apps/jobposition/lib/helper.php');
JLoader::register("PCompanyModelThirdAccounts", OC::$SERVERROOT."/apps/company/lib/thirdaccounts.php");


$LoginStats = PUtil::checkUserLogin(true);
if ($LoginStats !== true) {
   echo $LoginStats;
   exit();
}

OCP\JSON::callCheck();

$companyid = PFactory::getMasterUser()->id;
$jobcityList = PResumesHelper::getJobCityList($companyid);
$folderList = PJobpositionHelper::getCustomFolderList($companyid, 0, 'user', true);

$type = JRequest::getString('type','');
$syncaction = JRequest::getString('syncaction','');
$edit = JRequest::getInt('edit',0);
$loginstatus = JRequest::getInt('loginstatus',0);


$userfolderids = PCompanyHelper::getAutoRenewfolderid();
$autorenewfolderid = !empty($userfolderids['autorenewjobs_'.$type]) ? $userfolderids['autorenewjobs_'.$type] : '';

$selectjobtitle = "";
$curcityids = array();
$curfolderid = "";
if(!empty($autorenewfolderid)){
   list($selectjobtitle,$curcityids,$curfolderid) = PCompanyHelper::getSelectJobTitle($autorenewfolderid);
}

if(PFactory::isMasterUser()){
   $user_id = $companyid;
}else{
   $user_id = OC_User::getUser();
}

$dirInfo = PJobpositionHelper::getDirInfo($autorenewfolderid, $user_id);


$tmpl = new OCP\Template('company', 'part.positionselect', '');
$tmpl->assign('jobcityList', $jobcityList);
$tmpl->assign('folderList', $folderList);
$tmpl->assign('type', $type);
$tmpl->assign('syncaction', $syncaction);
$tmpl->assign('curfolderid', $curfolderid);
$tmpl->assign('edit', $edit);
$tmpl->assign('loginstatus', $loginstatus);
$tmpl->assign('selectjobtitle', $selectjobtitle);
$tmpl->assign('curcityids', $curcityids);
$tmpl->assign('dirInfo', $dirInfo);
$tmpl->assign('autorenewfolderid', $autorenewfolderid);

$tmpl->printpage();